var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/regenerator")), e = require("../../@babel/runtime/helpers/asyncToGenerator"), a = require("../../utils/tool"), r = require("../../http/indexApi.js"), n = getApp();

Page({
    data: {
        orderNo: "",
        code: "",
        weChatData: {
            encryptedData: "",
            iv: ""
        }
    },
    onLoad: function(a) {
        var r = this;
        return e(t.default.mark(function e() {
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    r.setData({
                        orderNo: a.orderNo
                    });

                  case 1:
                  case "end":
                    return t.stop();
                }
            }, e);
        }))();
    },
    toRobotOrder: function() {
        wx.navigateTo({
            url: "/pages/robot_order/robot_order?orderNo=".concat(this.data.orderNo)
        });
    },
    toRobotLogin: function() {},
    showCaptcha: function() {
        this.selectComponent("#captcha").show();
    },
    oauth: function(r) {
        var n = this;
        return e(t.default.mark(function o() {
            return t.default.wrap(function(o) {
                for (;;) switch (o.prev = o.next) {
                  case 0:
                    if (r.detail.encryptedData) {
                        o.next = 3;
                        break;
                    }
                    return (0, a.toastToPage)("用户取消授权"), o.abrupt("return");

                  case 3:
                    return o.t0 = n, o.t1 = {
                        encryptedData: r.detail.encryptedData,
                        iv: r.detail.iv
                    }, o.next = 7, (0, a.getWechatLoginCode)();

                  case 7:
                    o.t2 = o.sent, o.t3 = {
                        weChatData: o.t1,
                        code: o.t2
                    }, o.t0.setData.call(o.t0, o.t3), wx.showLoading({
                        mask: !0,
                        title: "加载中…"
                    }), wx.checkSession({
                        success: function() {
                            var a = e(t.default.mark(function e(a) {
                                return t.default.wrap(function(t) {
                                    for (;;) switch (t.prev = t.next) {
                                      case 0:
                                        wx.hideLoading(), n.showCaptcha();

                                      case 2:
                                      case "end":
                                        return t.stop();
                                    }
                                }, e);
                            }));
                            return function(t) {
                                return a.apply(this, arguments);
                            };
                        }(),
                        fail: function() {
                            var r = e(t.default.mark(function e(r) {
                                return t.default.wrap(function(t) {
                                    for (;;) switch (t.prev = t.next) {
                                      case 0:
                                        return t.t0 = n, t.next = 3, (0, a.getWechatLoginCode)();

                                      case 3:
                                        t.t1 = t.sent, t.t2 = {
                                            code: t.t1
                                        }, t.t0.setData.call(t.t0, t.t2), n.showCaptcha();

                                      case 7:
                                      case "end":
                                        return t.stop();
                                    }
                                }, e);
                            }));
                            return function(t) {
                                return r.apply(this, arguments);
                            };
                        }()
                    });

                  case 12:
                  case "end":
                    return o.stop();
                }
            }, o);
        }))();
    },
    register: function(o) {
        var c = this;
        return e(t.default.mark(function e() {
            var i;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, wx.showLoading({
                        mask: !0,
                        title: "加载中…"
                    }), console.log("sourceInfo2:", n.data.sourceInfo), t.next = 5, r.wxPhoneLogin(c.data.code, c.data.weChatData.encryptedData, c.data.weChatData.iv, c.fromUserID, o.detail.captchaVerification, n.data.sourceInfo);

                  case 5:
                    i = t.sent, n.globalData.token = i.data.token, n.data.loginInfo = i.data, wx.setStorageSync("token", i.data.token), 
                    wx.setStorage({
                        key: "LoginInfo",
                        data: n.data.loginInfo
                    }), n.linkSocket(), (0, a.toastToPage)("登录成功"), wx.reLaunch({
                        url: "/pages/robot_order/robot_order?orderNo=".concat(c.data.orderNo)
                    }), t.next = 18;
                    break;

                  case 15:
                    t.prev = 15, t.t0 = t.catch(0), (0, a.toastToPage)(t.t0.msg);

                  case 18:
                    return t.prev = 18, wx.hideLoading(), t.finish(18);

                  case 21:
                  case "end":
                    return t.stop();
                }
            }, e, null, [ [ 0, 15, 18, 21 ] ]);
        }))();
    }
});